package com.example.config;

import com.sun.corba.se.impl.orb.PrefixParserAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@Slf4j
@SpringBootApplication
public class ConfigApplication {

    public static void main(String[] args) throws Exception{

        ApplicationContext context = SpringApplication.run(ConfigApplication.class, args);

       // log.error("出错了，假的");
        log.debug("调试");
        log.info("信息");
        log.warn("警告");
        log.error("错误");

        DataSource dataSource = context.getBean(DataSource.class);
        try(Connection c = dataSource.getConnection()){
            String sql = "select uid,username,password from users order by uid limit 5";
            try(PreparedStatement ps = c.prepareStatement(sql)){
                log.debug("执行sql:"+sql);

                try(ResultSet rs = ps.executeQuery()){
                    while(rs.next()){
                        log.info("uid = {},username = {},password = {}",
                                rs.getInt("uid"),
                                rs.getString("username"),
                                rs.getString("password"));
                    }
                }
            }
        }

    }

}
